#ifndef POLYGON_GRAPHIC_ITEM
#define POLYGON_GRAPHIC_ITEM

#include <QtGui/QGraphicsPolygonItem>
#include <QtGui/QPainter>
#include <QtGui/QStyleOptionGraphicsItem>

namespace gui
{

class PolygonGraphicItem : public QGraphicsPolygonItem
{
public:
    PolygonGraphicItem(bool antiAlias = true, bool defaultSelection = false,
        QGraphicsItem* parent = 0) : QGraphicsPolygonItem(parent),
            m_aa(antiAlias),
            m_defaultSelection(defaultSelection)
    {
    }

    PolygonGraphicItem(const QPolygonF& polygon, bool antiAlias = true,
        bool defaultSelection = false, QGraphicsItem* parent = 0) :
            QGraphicsPolygonItem(polygon, parent),
            m_aa(antiAlias),
            m_defaultSelection(defaultSelection)
    {
    }

    virtual ~PolygonGraphicItem() {}

protected:
    virtual void paint(QPainter* painter,
        const QStyleOptionGraphicsItem* option, QWidget* widget)
    {
        QStyleOptionGraphicsItem _option = QStyleOptionGraphicsItem(*option);

        if (!m_defaultSelection)
        {
            _option.state &= ~QStyle::State_Selected;
        }

        if (m_aa)
        {
            painter->setRenderHint(QPainter::Antialiasing);
        }

        QGraphicsPolygonItem::paint(painter, &_option, widget);
    }

protected:
    bool antialiasing() const
    {
        return m_aa;
    }

    void setAntialiasing(bool enabled)
    {
        m_aa = enabled;
    }

    bool defaultSelection() const
    {
        return m_defaultSelection;
    }

    void setDefaultSelection(bool enabled)
    {
        m_defaultSelection = enabled;
    }

private:
    bool m_aa;
    bool m_defaultSelection;
};

} // namespace gui

#endif
